package com.mcy.view.locateview;

import java.util.ArrayList;
import java.util.List;
import com.mcy.study.R;
import com.mcy.view.ext.SatelliteMenu;
import com.mcy.view.ext.SatelliteMenu.SateliteClickedListener;
import com.mcy.view.ext.SatelliteMenuItem;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;
import android.widget.Toast;

public class LocationViewActivity extends Activity {
	private boolean l2show = false;
	private boolean l1show = false;
	
	private LocateToolView locateToolView;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_location_view);
		
		RelativeLayout root = (RelativeLayout)findViewById(R.id.root);
		
	    final LocateView locateView = new LocateView(getBaseContext());
		LayoutParams params = 
				new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT);
		locateView.setLayoutParams(params);

		root.addView(locateView);
		locateView.setVisibility(View.GONE);
		
		
		locateToolView = (LocateToolView)findViewById(R.id.locate);
	    locateToolView.setVisibility(View.GONE);
		
		
        SatelliteMenu menu = (SatelliteMenu) findViewById(R.id.menu);
        
        List<SatelliteMenuItem> items = new ArrayList<SatelliteMenuItem>();
        items.add(new SatelliteMenuItem(4, R.drawable.ic_1));
        items.add(new SatelliteMenuItem(4, R.drawable.ic_3));
        items.add(new SatelliteMenuItem(4, R.drawable.ic_4));
        items.add(new SatelliteMenuItem(3, R.drawable.ic_5));//l1
        items.add(new SatelliteMenuItem(2, R.drawable.ic_6));//l2
        items.add(new SatelliteMenuItem(1, R.drawable.ic_2));
//        items.add(new SatelliteMenuItem(5, R.drawable.sat_item));
        menu.addItems(items);        
        
        menu.setOnItemClickedListener(new SateliteClickedListener() {
			
			public void eventOccured(int id) {
				switch (id) {
				case 2:
					if(l2show==true){
						locateToolView.setVisibility(View.GONE);
						l2show = false;
					}else{
						locateToolView.setVisibility(View.VISIBLE);
						l2show = true;
					}
					Toast.makeText(getBaseContext(),String.valueOf(locateToolView.centerX)
							+","+String.valueOf(locateToolView.centerY), Toast.LENGTH_SHORT).show();
					break;
				case 3:
					if(l1show==true){
						locateView.setVisibility(View.GONE);
						l1show = false;
					}else{
						locateView.setVisibility(View.VISIBLE);
						l1show = true;
					}
					Toast.makeText(getBaseContext(),String.valueOf(locateView.getCenterX())
							+","+String.valueOf(locateView.getCenterY()), Toast.LENGTH_SHORT).show();
					break;

				default:
					break;
				}
				
			}
		});
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.location_view, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
}
